
	/************************************************************************************************

	  Liquid Loader

		1-liquid-url detection
	  2-read the debug option
	  3-load the jsl module

	*************************************************************************************************/

	//-------------------------------------------------------------------------------
	;(function() {
		var mod, cs, re, src, csrc, url, qs, mode, log, p, node

		try {

			mod = '[jsl-mod]'

			//1-web
			//-------------------------------------------------------------------------------
			if(this["@liquidbox"]) {

			}
			else {

				//1.1-Liquid url detection
				//-------------------------------------------------------------------------------
				cs = document.getElementsByTagName("script")
				re = /liquid\d+\.js$/

				for(var a = 0, l = cs.length; a < l; a++) {

					csrc	= cs[a].src.replace(/\s+/g, "")
					src		= csrc.split(/\?|#/)[0]

					if(re.test(src)) {

						if(url) {
							url = null
							break
						}

						qs	= csrc.match(/\?[^#]+/)
						url	= true
					}
				}

				//ambiguity
				if(url === null)	throw Error("unable to locate the liquid URL (found a number of possible matches)")
				if(!url)					throw Error("unable to locate the liquid URL")

				//1.2-readonly options exposed as infos
				//-------------------------------------------------------------------------------
				qs 		= qs && qs[0]
				mode 	= qs && qs.match(/(?:\?|&)mode=([^&]*)/i)
				log 	= qs && qs.match(/(?:\?|&)log=([^&]*)/i)

				if(mode) {
					mode = mode[1].match(/^(debug|release)$/i)
					mode = mode && mode[1]
					if(!mode)	throw Error("found bad value in the [mode] option, expected: debug,release")
				}

				if(log) {
					log = log[1].match(/^(none|error|warn|info|log|debug)$/i)
					if(!log)	throw Error("found bad value in the [log] option, expected: none,error,warn,info,log,debug")
				}

				//1.3-module load
				//-------------------------------------------------------------------------------
				if(mode && mode.toLowerCase() === "release")
					mod = mod.replace(/"\[jsl-d\]"/									, "false").
										replace(/\/\*!\*\/[\s\S]+?\/\*!\*\//g	,	"").
										replace(/\/\/![\s\S]+?\/\/!.*\n/g			, "")

				p = document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]
				if(!p)	throw Error("header/body nodes not found")

				node 			= document.createElement("script")
				node.text = mod

				p.appendChild(node)
				p.removeChild(node)
			}
		}
		catch(e) {
			throw Error("Liquid(error) >> failed to load jsl module - cause: " + e)
		}
	})();
